package cn.edu.gdpt.mobile0123456789hwh0410;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
//    一、控件初始化
    private RecyclerView rvMainStudent;
    private List<Student> list;//声明数据集
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
//        设置控件的布局方式为线性布局
        rvMainStudent.setLayoutManager(new LinearLayoutManager(this));
//        定义适配器对象
        StudentRVAdapter adapter=new StudentRVAdapter(list);
//       给列表控件设置适配器对象
        rvMainStudent.setAdapter(adapter);
    }
    private void initData() {
        list=new ArrayList<>();//创建集合类对象，并初始化数据
        list.add(new Student("小明",20,"移动1班","13500001111"));
        list.add(new Student("小洪",19,"移动2班","13500001112"));
        list.add(new Student("小丽",21,"移动3班","13500001113"));
        list.add(new Student("小青",23,"移动4班","13500001114"));
        list.add(new Student("小张",22,"移动5班","13500001115"));
        list.add(new Student("小李",20,"移动6班","13500001116"));
    }
    private void initView() {
        rvMainStudent = (RecyclerView) findViewById(R.id.rvMainStudent);
    }
}